/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import controller.Action;
import java.io.IOException;
import java.sql.SQLDataException;
import java.sql.SQLException;
import javax.imageio.IIOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Conta;
import persistence.OperacaoDAO;

/**
 *
 * @author Leandro
 */
public class OperacaoSaldoAction implements Action{

    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response, Integer contaLogada) throws IIOException {
            
         String numeroConta = "";
            if("".equals(contaLogada)){
               numeroConta = request.getParameter("numeroConta");
            }else{
                numeroConta = contaLogada.toString();
            }
            
            if("".equals(numeroConta)){
                try {
                    response.sendRedirect("indexErro.xhtml");
                } catch (IOException ex) {
                    
                }
            }
            else{                
                Conta conta = new Conta();
                conta.setNumero(Integer.parseInt(numeroConta));
                try {
                    float saldoConta = OperacaoDAO.getInstace().recuperaSaldo(conta);                            
                    request.setAttribute("saldo", saldoConta);
                    request.setAttribute("numeroConta", numeroConta);
                    RequestDispatcher dispatcher = request.getRequestDispatcher("ExibeSaldo.jsp");
                    dispatcher.forward(request, response);
                } catch (SQLDataException ex) {                    
                } catch (ClassNotFoundException ex) {                                        
                } catch (SQLException ex) {                    
                } catch (ServletException ex) {                    
                } catch (IOException ex) {                    
                }                
            }
    }

    
}
